package com.spark.sniffer.plugin.plugins.define.trace;

import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;

import com.spark.sniffer.plugin.interceptor.InstanceMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.StaticMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine;
import com.spark.sniffer.plugin.match.ClassMatch;
import com.spark.sniffer.plugin.match.NameMatch;
import com.spark.sniffer.plugin.plugins.interceptor.HttpUtilsInterceptor;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class HttpUtilsPlugin extends ClassStaticMethodsEnhancePluginDefine {

    @Override
    protected ClassMatch enhanceClass() {
        return NameMatch.byName("com.spark.teaching.common.utils.HttpUtils");
    }

    @Override
    protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
        return null;
    }

    @Override
    protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
        return new StaticMethodsInterceptPoint[] {new StaticMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                // tryTo是teaching-backend的
                // doRequest是teaching-o2o的
                return nameStartsWith("tryTo").or(named("doRequest"));
            }

            @Override
            public Class<?> getMethodsInterceptor() {
                return HttpUtilsInterceptor.class;
            }

            @Override
            public boolean isOverrideArgs() {
                return true;
            }
        }};
    }

}
